﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;

namespace Spacer {
	public class Range<T> where T : new() {
		T m_TMin;
		T m_TMax;

		public T Min { get { return m_TMin; } set { m_TMin = value; } }
		public T Max { get { return m_TMax; } set { m_TMax = value; } }
		public Range() { m_TMin = new T(); m_TMax = new T(); }
		public Range( T value ) { m_TMin = value; m_TMax = value; }
		public Range( T min, T max ) { m_TMin = min; m_TMax = max; }
	}

	public class DRange {
		double m_dMin;
		double m_dMax;

		public double Min { get { return m_dMin; } set { m_dMin = value; } }
		public double Max { get { return m_dMax; } set { m_dMax = value; } }
		public bool Contains( double value ) { return value > m_dMin && value < m_dMax; }
		public bool Intersects( double value ) { return value >= m_dMin && value <= m_dMax; }
		public DRange() { m_dMin = 0; m_dMax = 0; }
		public DRange( double value ) { m_dMin = value; m_dMax = value; }
		public DRange( double min, double max ) { m_dMin = min; m_dMax = max; }
	}
	
	public class FRange {
		float m_fMin;
		float m_fMax;

		public float Min { get { return m_fMin; } set { m_fMin = value; } }
		public float Max { get { return m_fMax; } set { m_fMax = value; } }
		public bool Contains( float value ) { return value > m_fMin && value < m_fMax; }
		public bool Intersects( float value ) { return value >= m_fMin && value <= m_fMax; }
		public FRange() { m_fMin = 0; m_fMax = 0; }
		public FRange( float value ) { m_fMin = value; m_fMax = value; }
		public FRange( float min, float max ) { m_fMin = min; m_fMax = max; }
	}
	
	public class IRange {
		int m_iMin;
		int m_iMax;

		public int Min { get { return m_iMin; } set { m_iMin = value; } }
		public int Max { get { return m_iMax; } set { m_iMax = value; } }
		public bool Contains( int value ) { return value > m_iMin && value < m_iMax; }
		public bool Intersects( int value ) { return value >= m_iMin && value <= m_iMax; }
		public IRange() { m_iMin = 0; m_iMax = 0; }
		public IRange( int value ) { m_iMin = value; m_iMax = value; }
		public IRange( int min, int max ) { m_iMin = min; m_iMax = max; }
	}

	// ----------------------------------------------------------------------------------------------------

	public class FRectangle {
		float m_fX;
		float m_fY;
		float m_fW;
		float m_fH;

		public float X {
			get { return m_fX; }
			set { m_fX = value; }
		}

		public float Y {
			get { return m_fY; }
			set { m_fY = value; }
		}

		public float Width {
			get { return m_fW; }
			set { m_fW = value; }
		}

		public float Height {
			get { return m_fH; }
			set { m_fH = value; }
		}

		public float Left {
			get { return m_fX; }
			set { m_fX = (value <= (m_fX + m_fW) ? value : m_fX); }
		}

		public float Top {
			get { return m_fY; }
			set { m_fY = (value <= (m_fY + m_fH) ? value : m_fY); }
		}

		public float Right {
			get { return m_fX + m_fW; }
			set { m_fW = (value >= m_fX ? value-m_fX : m_fW); }
		}

		public float Bottom {
			get { return m_fY + m_fH; }
			set { m_fH = (value >= m_fY ? value-m_fY : m_fH); }
		}
	}
}
